package com.xinxin.intelligenceexam.api;

/**
 * Created by liukun on 16/3/10.
 */
public class ApiException extends RuntimeException {

    public static final int FAIL = 0;
    public static final int SUCCESS = 1;
    public static final int NO_DATA = 2;

    public ApiException(int resultCode) {
        this(getApiExceptionMessage(resultCode));
    }

    public ApiException(String detailMessage) {
        super(detailMessage);
    }

    /**
     * 由于服务器传递过来的错误信息直接给用户看的话，用户未必能够理解
     * 需要根据错误码对错误信息进行一个转换，在显示给用户
     * @param code
     * @return
     */
    private static String getApiExceptionMessage(int code){
        String message = "";
        switch (code) {
            case FAIL:
                message = "获取数据失败";
                break;
            case NO_DATA:
                message = "没有数据";
                break;
            case SUCCESS:
                message = "成功";//不应该存在的状态啊
                break;
            default:
                message = "未知错误";

        }
        return message;
    }
}

